package com.fs.service.bo.purchase;

import com.fs.entity.PurchaseState;

import java.time.LocalDateTime;

public enum Status {
    NotPayed,//未支付
    Expired,//过期未支付
    ToBeUsed,//待使用
    NotUsed,//未使用
    HasUsed;//已使用

    public static Status transfer(PurchaseState state, LocalDateTime beginTime, LocalDateTime endTime) {
        switch (state) {
            case Used:
                return HasUsed;
            case NotPayed:
                if (LocalDateTime.now().isAfter(beginTime)) {
                    return Expired;
                }
                return NotPayed;
            case HasPayed:
                if (LocalDateTime.now().isAfter(endTime)) {
                    return NotUsed;
                }
                return ToBeUsed;
            default:
                throw new RuntimeException("转换enum异常");
        }
    }
}
